﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SkeletonNET.Base.Crud.UnitOfWork
{
    public interface IUnitOfWork : IDisposable
    {
        /// <summary>
        /// Save all the data
        /// </summary>
        void Commit();
        /// <summary>
        /// Attach an entity to the context
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="entity">The entity to attach.</param>
        void Attach<TEntity>(TEntity entity) where TEntity : class;
        /// <summary>
        /// Add an entity to the context.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="entity">The entity to add.</param>
        /// <returns>Reference to the added entity;</returns>
        TEntity Add<TEntity>(TEntity entity) where TEntity : class;
        /// <summary>
        /// Create a query to fetch an IQueryable list from the context.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <returns>IQueryble with TEntity items</returns>
        IQueryable<TEntity> GetQuery<TEntity>() where TEntity : class;
        /// <summary>
        /// Update an existing entity
        /// </summary>
        /// <typeparam name="TEntity">Type of the entity</typeparam>
        /// <param name="entity">The entity to update</param>
        /// <returns>Return instance to the updated entity.</returns>
        TEntity Update<TEntity>(TEntity entity) where TEntity : class;
        /// <summary>
        /// Remove an entity from the context.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="entity">The entity to remove.</param>
        void Remove<TEntity>(TEntity entity) where TEntity : class;
    }
}
